package com.windsea.relationshipmining.activity;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.windsea.relationshipmining.R;
import com.windsea.relationshipmining.model.Relationship;

public class RelationshipAdapter extends BaseAdapter {
	private Context mContext;
	private List<Relationship> list_item;

	public RelationshipAdapter(Context c, List<Relationship> obj) {
		mContext = c;
		this.list_item = obj;
	}

	public int getCount() {
		return this.list_item.size();
	}

	public Object getItem(int position) {
		return null;
	}

	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View v = convertView;
		if (v == null) {
			LayoutInflater inflater = LayoutInflater.from(mContext);
			v = inflater.inflate(R.layout.listitem_contact, null);
		}
		Relationship rs = this.list_item.get(position);
		if (rs != null) {
			TextView name = (TextView) v.findViewById(R.id.name);
			name.setText(rs.getContactName());
			ImageView imgV = (ImageView) v.findViewById(R.id.imgLabeled);

			if (rs.getContactRelation() != null) {
				imgV.setVisibility(ImageView.VISIBLE);
			} else {
				imgV.setVisibility(ImageView.GONE);

			}
		}

		return v;
	}

	public void clearAdapter() {
		list_item.clear();
		notifyDataSetChanged();
	}

	public void addAll(ArrayList<Relationship> arr) {
		list_item.addAll(arr);
		notifyDataSetChanged();
	}
}
